package com.ymttest.database.mongo;

import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.ymt.core.tool.FormatUtil;
import com.ymt.database.MongoDBDriver;
import com.ymttest.utils.EnvSetup;

public class MQMessageStatusWapper {
	MongoDBDriver mdd;

	public MQMessageStatusWapper() throws Exception {
				}
	
	/**
	 * 用uid查询AccessToken
	 * 
	 * @param uid
	 * @return AccessToken
	 * @throws Exception
	 */
	public List<MQMessageStatusBean> getStatusByMid(String appName,String mid) throws Exception {
		SimpleDateFormat   sDateFormat   =   new   SimpleDateFormat("yyyyMM");   
		String   date   =   sDateFormat.format(new   java.util.Date());  
		mdd = new MongoDBDriver(EnvSetup.getSystemUrl("set5_mongoip_noauth"), Integer.valueOf(EnvSetup
				.getSystemUrl("set5_mongoport_noauth")), "JMQ_Message_Status_"+date);		

		mdd.selectCollection("mq_subscribe_"+appName);		
	
		String re = null;
		List<MQMessageStatusBean> mbs = new ArrayList<>();
		
		MQMessageStatusBean mb = null;
		
		ArrayList<String> list = mdd.selectPartLimit("{\"mid\":\"" + mid + "\"}",10000);
		try {
			for(int i=0;i<list.size();i++) {
				re = list.get(i);
				mb = (MQMessageStatusBean) FormatUtil.GSONToObject(re, MQMessageStatusBean.class);
				mbs.add(mb);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		mdd.close();
		return mbs;
	}
	
	public static void main(String args[])
	{
		try {
			List<MQMessageStatusBean> MessageBean =new MQMessageStatusWapper().getStatusByMid("testbamei","8661596641");
//			Logger.comment(MessageBean.getBody());
//			Logger.comment(MessageBean.getCtime().toString());
			Logger.comment(MessageBean.size()+"");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
